#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef unsigned long LONG;


/* main
 *  * */
int main() {
	short N;
	cin >> N;
	do {
		long double A=1; 
		LONG D=0; 

		while(fmod(A,N)!=0) {
			A = (A*10) + 1; 
			A=fmod(A,N); 
			D++; 
		} 
		cout << D+1 << endl;
		cin >> N;
	} while(cin.eof() == false);
	return 0;
}
